load("//bazel:mongo_src_rules.bzl", "mongo_cc_benchmark", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "op_observer",
    srcs = [
        "op_observer.cpp",
        "op_observer_registry.cpp",
    ],
    hdrs = [
        "op_observer.h",
        "op_observer_noop.h",
        "op_observer_registry.h",
        "//src/mongo/base:data_type_validated.h",
        "//src/mongo/bson:bsonelement_comparator.h",
        "//src/mongo/crypto:aead_encryption.h",
        "//src/mongo/crypto:fle_crypto_predicate.h",
        "//src/mongo/crypto:fle_crypto_types.h",
        "//src/mongo/crypto:fle_data_frames.h",
        "//src/mongo/crypto:fle_key_types.h",
        "//src/mongo/crypto:fle_stats_gen",
        "//src/mongo/crypto:fle_tokens.h",
        "//src/mongo/crypto:symmetric_crypto.h",
        "//src/mongo/crypto:symmetric_key.h",
        "//src/mongo/db:keypattern.h",
        "//src/mongo/db:yieldable.h",
        "//src/mongo/db/catalog:collection.h",
        "//src/mongo/db/catalog:index_catalog.h",
        "//src/mongo/db/catalog:index_catalog_entry.h",
        "//src/mongo/db/collection_crud:capped_visibility.h",
        "//src/mongo/db/exec:shard_filterer.h",
        "//src/mongo/db/exec:working_set.h",
        "//src/mongo/db/exec:working_set_common.h",
        "//src/mongo/db/exec/document_value:document_comparator.h",
        "//src/mongo/db/exec/document_value:value_comparator.h",
        "//src/mongo/db/exec/sbe/values:bson.h",
        "//src/mongo/db/exec/sbe/values:key_string_entry.h",
        "//src/mongo/db/exec/sbe/values:value.h",
        "//src/mongo/db/fts:fts_basic_phrase_matcher.h",
        "//src/mongo/db/fts:fts_language.h",
        "//src/mongo/db/fts:fts_matcher.h",
        "//src/mongo/db/fts:fts_phrase_matcher.h",
        "//src/mongo/db/fts:fts_query_impl.h",
        "//src/mongo/db/fts:fts_spec.h",
        "//src/mongo/db/fts:fts_tokenizer.h",
        "//src/mongo/db/fts:fts_unicode_phrase_matcher.h",
        "//src/mongo/db/fts:stemmer.h",
        "//src/mongo/db/fts:stop_words.h",
        "//src/mongo/db/fts:tokenizer.h",
        "//src/mongo/db/index:index_descriptor.h",
        "//src/mongo/db/index:index_descriptor_fwd.h",
        "//src/mongo/db/index_builds:commit_quorum_options.h",
        "//src/mongo/db/matcher:expression_leaf.h",
        "//src/mongo/db/matcher:expression_parser.h",
        "//src/mongo/db/matcher:expression_path.h",
        "//src/mongo/db/matcher:expression_text_base.h",
        "//src/mongo/db/matcher:expression_tree.h",
        "//src/mongo/db/matcher:expression_type.h",
        "//src/mongo/db/matcher:expression_where_base.h",
        "//src/mongo/db/matcher:expression_with_placeholder.h",
        "//src/mongo/db/matcher:extensions_callback.h",
        "//src/mongo/db/matcher:extensions_callback_noop.h",
        "//src/mongo/db/matcher:in_list_data.h",
        "//src/mongo/db/matcher:matcher_type_set.h",
        "//src/mongo/db/matcher/schema:encrypt_schema_gen",
        "//src/mongo/db/matcher/schema:encrypt_schema_types.h",
        "//src/mongo/db/matcher/schema:expression_internal_schema_allowed_properties.h",
        "//src/mongo/db/matcher/schema:json_pointer.h",
        "//src/mongo/db/pipeline:accumulator_percentile_enum_gen",
        "//src/mongo/db/pipeline:document_path_support.h",
        "//src/mongo/db/pipeline:document_source_change_stream_gen",
        "//src/mongo/db/pipeline:expression.h",
        "//src/mongo/db/pipeline:expression_context.h",
        "//src/mongo/db/pipeline:expression_visitor.h",
        "//src/mongo/db/pipeline:expression_walker.h",
        "//src/mongo/db/pipeline:javascript_execution.h",
        "//src/mongo/db/pipeline:monotonic_expression.h",
        "//src/mongo/db/pipeline:percentile_algo.h",
        "//src/mongo/db/pipeline:percentile_algo_accurate.h",
        "//src/mongo/db/pipeline:percentile_algo_continuous.h",
        "//src/mongo/db/pipeline:percentile_algo_discrete.h",
        "//src/mongo/db/pipeline:resume_token.h",
        "//src/mongo/db/query:bson_typemask.h",
        "//src/mongo/db/query:distinct_command_gen",
        "//src/mongo/db/query:index_bounds.h",
        "//src/mongo/db/query:interval.h",
        "//src/mongo/db/query:query_feature_flags_gen",
        "//src/mongo/db/query:query_knob_configuration.h",
        "//src/mongo/db/query:sort_pattern.h",
        "//src/mongo/db/query:tailable_mode.h",
        "//src/mongo/db/query:tailable_mode_gen",
        "//src/mongo/db/query/collation:collator_factory_interface.h",
        "//src/mongo/db/query/util:deferred.h",
        "//src/mongo/db/query/util:make_data_structure.h",
        "//src/mongo/db/query/util:named_enum.h",
        "//src/mongo/db/repl:rollback.h",
        "//src/mongo/db/storage:bson_collection_catalog_entry.h",
        "//src/mongo/db/storage:duplicate_key_error_info.h",
        "//src/mongo/db/storage:durable_catalog_entry.h",
        "//src/mongo/db/storage:index_entry_comparison.h",
        "//src/mongo/db/storage:sorted_data_interface.h",
        "//src/mongo/db/transaction:integer_interval_set.h",
        "//src/mongo/db/transaction:transaction_operations.h",
        "//src/mongo/db/update:pattern_cmp.h",
        "//src/mongo/rpc:object_check.h",
        "//src/mongo/s:chunk.h",
        "//src/mongo/s:chunk_manager.h",
        "//src/mongo/s:shard_key_pattern.h",
        "//src/mongo/s:type_collection_common_types_gen",
        "//src/mongo/s/catalog:type_chunk.h",
        "//src/mongo/s/catalog:type_chunk_base_gen",
        "//src/mongo/s/catalog:type_chunk_range.h",
        "//src/mongo/s/catalog:type_chunk_range_base_gen",
        "//src/mongo/s/resharding:type_collection_fields_gen",
        "//src/mongo/scripting:engine.h",
        "//src/mongo/util:lazily_initialized.h",
        "//src/mongo/util:pcre.h",
        "//src/mongo/util:represent_as.h",
    ],
    header_deps = [
        "//src/mongo/db/fts/unicode:unicode",
        "//src/mongo/db/pipeline/process_interface:mongo_process_interface",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db/storage/key_string",
    ],
)

mongo_cc_library(
    name = "op_observer_util",
    srcs = [
        "op_observer_util.cpp",
    ],
    hdrs = [
        "op_observer_util.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/query/bson:dotted_path_support",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "operation_logger_transaction_proxy",
    srcs = [
        "operation_logger_transaction_proxy.cpp",
    ],
    hdrs = [
        "operation_logger.h",
        "operation_logger_transaction_proxy.h",
    ],
    header_deps = [
        "//src/mongo/db/op_observer:op_observer",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "operation_logger_mock",
    hdrs = [
        "operation_logger.h",
        "operation_logger_mock.h",
    ],
)

mongo_cc_library(
    name = "user_write_block_mode_op_observer",
    srcs = [
        "user_write_block_mode_op_observer.cpp",
    ],
    hdrs = [
        "user_write_block_mode_op_observer.h",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/s:user_writes_recoverable_critical_section",
    ],
)

mongo_cc_library(
    name = "find_and_modify_images_op_observer",
    srcs = [
        "find_and_modify_images_op_observer.cpp",
    ],
    hdrs = [
        "find_and_modify_images_op_observer.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:commands",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:document_validation",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/db/repl:image_collection_entry",
    ],
)

mongo_cc_library(
    name = "change_stream_pre_images_op_observer",
    srcs = [
        "change_stream_pre_images_op_observer.cpp",
    ],
    hdrs = [
        "change_stream_pre_images_op_observer.h",
    ],
    deps = [
        ":op_observer",
        "//src/mongo/db:change_stream_pre_images_collection_manager",
        "//src/mongo/db:server_base",
        "//src/mongo/db/pipeline:change_stream_preimage",
        "//src/mongo/db/repl:optime",
        "//src/mongo/db/transaction:transaction_operations",
    ],
)

mongo_cc_library(
    name = "fallback_op_observer",
    srcs = [
        "fallback_op_observer.cpp",
    ],
    hdrs = [
        "fallback_op_observer.h",
    ],
    deps = [
        ":batched_write_context",
        ":op_observer",
        ":op_observer_util",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db:vector_clock",
        "//src/mongo/db/catalog:collection_catalog",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/transaction",
        "//src/mongo/db/views:view_catalog_helpers",
    ],
)

mongo_cc_library(
    name = "op_observer_impl",
    srcs = [
        "op_observer_impl.cpp",
    ],
    hdrs = [
        "op_observer_impl.h",
        "operation_logger.h",
    ],
    deps = [
        ":batched_write_context",
        ":op_observer",
        ":op_observer_util",
        "//src/mongo/db:change_stream_serverless_helpers",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:multitenancy",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:collection_catalog",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/catalog:database_holder",
        "//src/mongo/db/catalog:import_collection_oplog_entry",
        "//src/mongo/db/commands:txn_cmd_request",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/index_builds:commit_quorum_options",
        "//src/mongo/db/repl:repl_server_parameters",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_operations",
        "//src/mongo/s:grid",
    ],
)

mongo_cc_library(
    name = "batched_write_context",
    srcs = [
        "batched_write_context.cpp",
    ],
    hdrs = [
        "batched_write_context.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/transaction:transaction_operations",
    ],
)

mongo_cc_library(
    name = "operation_logger_impl",
    srcs = [
        "operation_logger_impl.cpp",
    ],
    hdrs = [
        "operation_logger.h",
        "operation_logger_impl.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db/repl:oplog",
    ],
)

mongo_cc_library(
    name = "fcv_op_observer",
    srcs = [
        "fcv_op_observer.cpp",
    ],
    hdrs = [
        "fcv_op_observer.h",
    ],
    deps = [
        ":op_observer",
        ":op_observer_util",
        "//src/mongo:base",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/session:kill_sessions_local",
        "//src/mongo/executor:egress_connection_closer_manager",
    ],
)

mongo_cc_unit_test(
    name = "db_op_observer_test",
    srcs = [
        "batched_write_context_test.cpp",
        "batched_write_policy_test.cpp",
        "op_observer_impl_test.cpp",
        "op_observer_registry_test.cpp",
        "user_write_block_mode_op_observer_test.cpp",
    ],
    tags = ["mongo_unittest_second_group"],
    deps = [
        ":batched_write_context",
        ":change_stream_pre_images_op_observer",
        ":find_and_modify_images_op_observer",
        ":op_observer",
        ":op_observer_impl",
        ":op_observer_util",
        ":operation_logger_impl",
        ":user_write_block_mode_op_observer",
        "//src/mongo/db:change_stream_pre_images_collection_manager",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:read_write_concern_defaults",
        "//src/mongo/db:read_write_concern_defaults_mock",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db:shard_role",
        "//src/mongo/db:write_block_bypass",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/catalog:catalog_helpers",
        "//src/mongo/db/catalog:import_collection_oplog_entry",
        "//src/mongo/db/catalog:local_oplog_info",
        "//src/mongo/db/commands:create_command",
        "//src/mongo/db/concurrency:exception_util",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:oplog_interface_local",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/repl:storage_interface_impl",
        "//src/mongo/db/session:session_catalog_mongod",
        "//src/mongo/db/storage:recovery_unit_base",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_operations",
        "//src/mongo/idl:server_parameter_test_util",
    ],
)

mongo_cc_benchmark(
    name = "op_observer_bm",
    srcs = [
        "op_observer_bm.cpp",
    ],
    deps = [
        ":change_stream_pre_images_op_observer",
        ":fallback_op_observer",
        ":fcv_op_observer",
        ":find_and_modify_images_op_observer",
        ":op_observer",
        ":op_observer_impl",
        ":op_observer_util",
        ":operation_logger_impl",
        ":operation_logger_transaction_proxy",
        ":user_write_block_mode_op_observer",
        "//src/mongo/db:service_context_d",
        "//src/mongo/db/auth:auth_op_observer",
        "//src/mongo/db/auth:authserver",
        "//src/mongo/db/catalog:collection_mock",
        "//src/mongo/db/repl:primary_only_service",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/db/s:sharding_runtime_d",
        "//src/mongo/db/timeseries:timeseries_op_observer",
        "//src/mongo/idl:cluster_server_parameter_op_observer",
    ],
)
